package operations;

import entity.Student;
import entity.StudentList;

import java.util.Scanner;

// 删除学生信息
public class Del implements IOperation {

    @Override
    public Student work() {
        Search search = new Search();
        // 先查找到需要删除的学生
        Student student = search.work();

        Scanner in = new Scanner(System.in);
        if (student != null) {
            while (true) {
                System.out.println("是否要删除该学生信息? (y/n)");
                String check = in.next();
                if ("y".equals(check) || "Y".equals(check)) {
                    StudentList.getInstance().remove(student);
                    System.out.println("删除成功!");
                    break;
                } else if ("n".equals(check) || "N".equals(check)) {
                    System.out.println("取消删除");
                    break;
                } else {
                    System.out.println("输入错误, 请重新输入");
                }
            }
        }
        return null;
    }
}
